package com.tyk.bookstore.back.system.valid.annotation;

import com.tyk.bookstore.back.system.valid.type.UserFieldValidType;
import com.tyk.bookstore.back.system.valid.validator.UserFieldConstraintValidator;
import jakarta.validation.Constraint;
import jakarta.validation.Payload;

import java.lang.annotation.Documented;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
 * @author tyk
 * @description 校验通用字段（不校验NULL值）
 */
@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
@Repeatable(UserFieldValid.List.class)
@Retention(RUNTIME)
@Documented
@Constraint(validatedBy = UserFieldConstraintValidator.class)
public @interface UserFieldValid {
    UserFieldValidType[] value();

    String message() default "用户字段不合法";

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};

    @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
    @Retention(RUNTIME)
    @Documented
    @interface List {
        UserFieldValid[] value();
    }
}
